package work20241228;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zdl
 * @date 2024/12/28
 */
class Transaction{
    private int year; //交易时间
    private int value; //交易额

    public Transaction() {
    }

    public Transaction(int year, int value) {
        this.year = year;
        this.value = value;
    }

    /**
     * 获取
     * @return year
     */
    public int getYear() {
        return year;
    }

    /**
     * 设置
     * @param year
     */
    public void setYear(int year) {
        this.year = year;
    }

    /**
     * 获取
     * @return value
     */
    public int getValue() {
        return value;
    }

    /**
     * 设置
     * @param value
     */
    public void setValue(int value) {
        this.value = value;
    }

    public String toString() {
        return "Transaction{year = " + year + ", value = " + value + "}";
    }
}
public class Demo12 {
    public static void main(String[] args) {
        //题目12：找出2011年发生的所有交易， 并按交易额排序（从低到高）
        ArrayList<Transaction> list = new ArrayList<>();
        list.add(new Transaction(2011,3000));
        list.add(new Transaction(2011,2000));
        list.add(new Transaction(2011,1000));
        list.add(new Transaction(2011,500));
        list.add(new Transaction(2012,3000));
        List<Transaction> collect = list.stream()
                                        .filter(s -> s.getYear() == 2011)
                                        .sorted((t1, t2) -> Integer.compare(t1.getValue(), t2.getValue()))
                                        .collect(Collectors.toList());
        System.out.println(collect);
    }
}
